﻿/*
   Copyright 2012 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Flower.Services.Data
{
    /// <summary>
    /// Base type for directory script parameters.
    /// </summary>
    [DataContract(Namespace = XmlNamespace.Directory)]
    [KnownType(typeof(BoolScriptParameter))]
    [KnownType(typeof(IntScriptParameter))]
    [KnownType(typeof(DoubleScriptParameter))]
    [KnownType(typeof(StringScriptParameter))]
    [KnownType(typeof(DirectoryEntryScriptParameter))]
    [KnownType(typeof(BoolArrayScriptParameter))]
    [KnownType(typeof(IntArrayScriptParameter))]
    [KnownType(typeof(DoubleArrayScriptParameter))]
    [KnownType(typeof(StringArrayScriptParameter))]
    [KnownType(typeof(DirectoryEntryArrayScriptParameter))]
    public abstract class ScriptParameter
    {
        /// <summary>
        /// Parameter name.
        /// </summary>
        [DataMember]
        public string Name { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public abstract void AcceptVisitor(IScriptParameterVisitor visitor);
    }

    /// <summary>
    /// Boolean parameter.
    /// </summary>
    [DataContract]
    public class BoolScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public bool Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// Integer parameter.
    /// </summary>
    [DataContract]
    public class IntScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public int Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// Double parameter.
    /// </summary>
    [DataContract]
    public class DoubleScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public double Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// String parameter.
    /// </summary>
    [DataContract]
    public class StringScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public string Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// Directory entry parameter.
    /// </summary>
    [DataContract]
    public class DirectoryEntryScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public DirectoryEntry Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// Boolean array parameter.
    /// </summary>
    [DataContract]
    public class BoolArrayScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public IList<bool> Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// Integer array parameter.
    /// </summary>
    [DataContract]
    public class IntArrayScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public IList<int> Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// Double array parameter.
    /// </summary>
    [DataContract]
    public class DoubleArrayScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public IList<double> Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// String array parameter.
    /// </summary>
    [DataContract]
    public class StringArrayScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public IList<string> Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    /// <summary>
    /// Directory entry array parameter.
    /// </summary>
    [DataContract]
    public class DirectoryEntryArrayScriptParameter : ScriptParameter
    {
        /// <summary>
        /// Parameter value.
        /// </summary>
        [DataMember]
        public IList<DirectoryEntry> Value { get; set; }

        /// <summary>
        /// Visitor support.
        /// </summary>
        /// <param name="visitor">Object to visit.</param>
        public override void AcceptVisitor(IScriptParameterVisitor visitor)
        {
            visitor.Visit(this);
        }
    }
}
